<?php
namespace app\tadmin\controller\category;
use app\tadmin\controller\Controller as BaseController;
use app\tadmin\model\Category as CategoryModel;
use app\tadmin\model\ArticleSingle as SingleModel;
/**
 * 文档-单面
 * Class Index
 * @package app\tadmin\controller
 */
class Single extends BaseController{

    public function index(){
        if (!$this->request->isAjax()) {
            $category_id = input('category_id');
            $category = CategoryModel::get($category_id);
            $single = SingleModel::where('category_id' , $category['id'])->find();
            return $this->fetch('index' , compact('category' , 'single'));
        }
        $data = $this->postData('single');
        if(SingleModel::edit($data)){
            return $this->renderSuccess('更新成功', url('category/index'));
        }
        return $this->renderError('更新失败');
    }

}